using System;
using System.Data;
using System.Data.SqlClient;

#if SQL2005
namespace SBPweb.Data.SQL2005
{

	/// <summary>
	/// This class implements a factory wich is able create commands to delete
	/// entities to the database via stored procedure by its ID (Int32)
	/// </summary>
	public class DeleteCommandFactory : IDeleteFactory<Int32>
	{

		#region Private fields

		private string mCommandName;
		private string mIdParamName;

		#endregion

		#region Constructor logic

		/// <summary>
		/// Initializes a new DeleteCommandFactory instance
		/// </summary>
		/// <param name="storedProcCommandName">Name of the stroed procedure</param>
		public DeleteCommandFactory(string storedProcCommandName)
			: this(storedProcCommandName, "Id")
		{

		}

		/// <summary>
		/// Initializes a new DeleteCommandFactory instance
		/// </summary>
		/// <param name="storedProcCommandName">Name of the stored procedure</param>
		/// <param name="idParamName">Name of the Id parameter of the stored procedure</param>
		public DeleteCommandFactory(string storedProcCommandName, string idParamName)
		{
			mCommandName = storedProcCommandName;
			mIdParamName = idParamName;
		}

		#endregion

		#region IDeleteFactory<int> Members

		/// <summary>
		/// This method creates the command
		/// </summary>
		/// <param name="db">SqlDatabase db</param>
		/// <param name="id">Id of the entity (Int32)</param>
		/// <returns></returns>
		public SqlCommand ConstructDeleteCommand(SqlDatabase db, Int32 id)
		{
			SqlCommand command = db.GetStoredProcCommand(mCommandName);

			db.AddInParameter(command, mIdParamName, SqlDbType.Int, id);

			return command;
		}

		#endregion

		#region IDbToBusinessEntityNameMapper Members

		/// <summary>
		/// This method maps the parameter name of the stored procedure to entity property name
		/// </summary>
		/// <param name="dbParameter">parameter name</param>
		/// <returns>entity property name</returns>
		public string MapDbParameterToBusinessEntityProperty(string dbParameter)
		{
			return dbParameter;
		}

		#endregion
		
	}
}
#endif